package ru.mirent.exceptions;

public class CustomRuntimeException extends RuntimeException {
    private String attachment = "";
    private String message = "";

    public CustomRuntimeException() {
        super();
    }

    public CustomRuntimeException(String message) {
        super(message);
    }

    public static Builder builder() {
        return new Builder();
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();

        if (!message.isEmpty()) {
            stringBuilder
                    .append(System.lineSeparator())
                    .append("Сообщение: ")
                    .append(message);
        }

        if (!attachment.isEmpty()) {
            stringBuilder
                    .append(System.lineSeparator())
                    .append("Вложение: ")
                    .append(attachment);
        }

        return super.toString() + stringBuilder;
    }

    public static class Builder {
        private CustomRuntimeException customRuntimeException;

        private Builder() {
            customRuntimeException = new CustomRuntimeException();
        }

        public Builder message(String text) {
            customRuntimeException.message = text;
            return this;
        }

        public Builder attachment(String text) {
            customRuntimeException.attachment = text;
            return this;
        }

        public CustomRuntimeException build() {
            return customRuntimeException;
        }
    }
}
